package no.ntnu.fp.su;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import no.ntnu.fp.db.Database;
import no.ntnu.fp.mmi.MainWindowPanel;

/**
 * Main class
 * Inneholder bare static methods
 * 
 * @author stn
 *
 */
public class Main {
	

	/**
	 * Starter Watch
	 * 
	 * @param platId - Id til platform som skal startes
	 */
	public static void startWatch(int platId) {
		(new Watch(platId)).start();
	}
	
	/**
	 * Starter Master
	 */
	public static void startMaster() {
		(new Master()).start();
		
	}

	/**
	 * Main entry point for application
	 * 
	 * @param args - Not Implemented
	 */
	public static void main(String[] args) {
		ArrayList<Integer> platIDs = new ArrayList<Integer>();
		ArrayList<String> platNames = new ArrayList<String>();
		
		Database db = new Database();
		ResultSet rs;
		
		db.connect();
		try {
			rs = db.query("SELECT * FROM platform");
		} catch (NullPointerException e) {
			System.out.println("Failed to connect to db, quitting");
			e.printStackTrace();
			return;
		}
		
		
		try {
			while(rs.next()) {
				
				platIDs.add(rs.getInt(1));
				platNames.add(rs.getString(2));
			}
		} catch (SQLException e) {
			System.out.println("Failed to get platform data");
			e.printStackTrace();
		}
		db.disconnect();
		
		for(int i = 0;i < platIDs.size();i++) {
			System.out.println("" + platIDs.get(i) + ": " + platNames.get(i));
		}
		
		new MainWindowPanel(platIDs, platNames);

		System.out.println("Main done");
	}

}
